home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <stdio.h>
- #include <dos.h>
- #include "define.h"
- /* #include <cdrfrb.h> */
-
- #ifdef DEBUG
- main(int argc, char *argv[])
- {
- long int sec;
- char buf[2340];
- int i;
-
- if (argc > 1) {
- printf("input is %s\n", argv[1]);
- sec = atol(argv[1]);
- printf("read %lx sector\n", sec);
- printf("return is %x\n", cdr_read(0, sec, buf, 1));
- for (i=0; i<2048; i++) {
- printf("%2x", buf[i]);
- if ((i & 0x1f) == 0x1f) {
- puts("");
- }
- }
- }
- }
- #endif
-
- /* データの読み取り(論理セクタ指定) */
- /*
- * device_no: device number (Towns CD-ROM -> 0)
- * sector_number: 論理セクタ番号
- * buffer: 転送アドレス
- * count: 読み込みセクタ数
- * return: 0 -> 正常終了, 0以外 -> エラー
- */
-
- int cdr_read(int device_no, long int sector_number, char *buffer, u_int count)
- {
- union REGS reg;
- struct SREGS seg;
-
- if (buffer == NULL) {
- return -1;
- }
-
- segread(&seg);
- reg.h.ah = 0x05;
- reg.h.al = (0xC0 | (u_char) device_no);
- reg.x.cx = 0x0000;
- reg.h.cl = (u_char) (((u_long) sector_number) >> 16); /* High */
- reg.x.dx = (u_int) (sector_number & 0x00ffff); /* Low */
- reg.x.bx = count;
- reg.x.di = (u_int) buffer;
-
- int86x(0x93, ®, ®, &seg);
-
- if (reg.h.ah == 0) {
- return 0;
- } else if (reg.h.ah == 0x02) { /* device number error */
- return DEVERR;
- } else if (reg.h.ah == 0x10) { /* cd-da plaing */
- return DEVPLY;
- } else { /* (reg.h.ah == 0x80) hard ware error */
- return reg.x.cx;
- }
- }
-
- #define cdr_read2(device_no, sector_number, buffer, count) cdr_read(device_no, sector_number, buffer, count)
-